﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Crosland.Automotriz.Facade.Interface;
using Crosland.Automotriz.Facade.Facade;
using Crosland.Automotriz.Core;
using System.Configuration;
using Crosland.Automotriz.Logic.Linq;
namespace Crosland.Automotriz.Web.Repuestos
{
    public partial class wFrmSituacionArticuloDetalleReport : System.Web.UI.Page
    {
        iFacadeSistema cls_man_modelo_imagenlogic = new FacadeSistema();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) {
                                
                this.listarArticulo();
               
                this.validarSessiones();

                if (Session["sistema"] != null && Session["modelo"] != null)
                {
                    this.CargarModeloSistema();
                    string script = "ShowPopupModeloSistema();";
                    ScriptManager.RegisterStartupScript(this, typeof(Page), "carga", script, true);
                }
            }
        }

        void validarSessiones()
        {
            Session["sistema"] = Convert.ToInt32(Request.QueryString["idSistema"]);
            Session["modelo"] = Convert.ToInt32(Request.QueryString["idModelo"]);

        }

        void CargarModeloSistema()
        {
            try
            {
                 clsT_Man_SistemaLogic t_man_sistemaBL = new clsT_Man_SistemaLogic();

            List<T_MAN_SISTEMA> listaSistema = new List<T_MAN_SISTEMA>();
            var q = (from c in t_man_sistemaBL.listarSistema2()
                    where c.ID_SISTEMA == Convert.ToInt32(Request.QueryString["idSistema"])
                    select c).Take(1);
            listaSistema = q.ToList();

            clsTd_ModeloLogic t_man_ModeloBL = new clsTd_ModeloLogic();

            List<TD_MODELO> listaModelo = new List<TD_MODELO>();
            var m = (from c in t_man_ModeloBL.listar_filtro_S()
                     where c.ID_MODELO == Convert.ToInt32(Request.QueryString["idModelo"])
                     select c).Take(1);

            listaModelo = m.ToList();


            lblModelo0.Text = (listaModelo[0].DES_MODELO).ToString();
            lbldes_sistema.Text = (listaSistema[0].DES_SISTEMA).ToString();
            lbldes_sistema0.Text = (listaSistema[0].DES_SISTEMA_INGLES).ToString();

            Session["DES_SISTEMA"] = (listaSistema[0].DES_SISTEMA_INGLES).ToString();
            }
            catch 
            {
                
            }
        }

        void listarArticulo()
        {

            try


            {
           
                clsT_Man_Sistema_ModeloLogic t_man_sistema_modeloBL=new clsT_Man_Sistema_ModeloLogic();
                List<T_MAN_SISTEMA_MODELO> lista = new List<T_MAN_SISTEMA_MODELO>();
               var q = (from c in t_man_sistema_modeloBL.lista()
                        where c.ID_MODELO == Convert.ToInt32(Request.QueryString["idModelo"]) && c.ID_SISTEMA == Convert.ToInt32(Request.QueryString["idSistema"])
                       select c).Take(1);

               lista = q.ToList();

               imagen.ImageUrl = ConfigurationManager.AppSettings["RutaFotoSistema"] + "/" + (lista[0].DES_IMAGEN).ToString();

                gvPopDetalleArticulos.DataSource = cls_man_modelo_imagenlogic.listar_sistema_articulo(Convert.ToInt32(Request.QueryString["idSistema"]), Convert.ToInt32(Request.QueryString["idModelo"]));
                gvPopDetalleArticulos.DataBind();
                int nro_pagina = Convert.ToInt32(gvPopDetalleArticulos.GetRowValues(gvPopDetalleArticulos.FocusedRowIndex, "NRO_PAGINA"));
                lblnropagina.Text = nro_pagina.ToString();

                Session["DES_URL"] = ConfigurationManager.AppSettings["RutaFotoSistema"] + "/" + (lista[0].DES_IMAGEN).ToString();
            }
            catch
            {


            }
        }

        protected void gvPopDetalleArticulos_AfterPerformCallback(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewAfterPerformCallbackEventArgs e)
        {

        }
    }
}